package com.ecmcloud.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ecmcloud.common.dto.IndexPageStatistics;
import com.ecmcloud.common.dto.Result;
import com.ecmcloud.entity.ProcessInstanceCopy;
import com.ecmcloud.entity.ProcessInstanceRecord;
import com.ecmcloud.service.IBaseService;
import com.ecmcloud.service.IProcessInstanceCopyService;
import com.ecmcloud.service.IProcessInstanceRecordService;
import com.ecmcloud.utils.CoreHttpUtil;

import cn.dev33.satoken.stp.StpUtil;

@Component
public class BaseServiceImpl implements IBaseService {

	@Autowired
    private IProcessInstanceCopyService processCopyService;
    
	@Autowired
    private IProcessInstanceRecordService processInstanceRecordService;

    /**
     * 首页数据
     *
     * @return
     */
    @Override
    public Result<IndexPageStatistics> index() {
        String userId = StpUtil.getLoginIdAsString();
        Long coypNum = processCopyService.lambdaQuery().eq(ProcessInstanceCopy::getUserId, userId).count();
        Long startendNum = processInstanceRecordService.lambdaQuery().eq(ProcessInstanceRecord::getUserId, userId).count();
        IndexPageStatistics indexPageStatistics = CoreHttpUtil.querySimpleData(userId).getData();
        indexPageStatistics.setCopyNum(coypNum);
        indexPageStatistics.setStartedNum(startendNum);
        return Result.success(indexPageStatistics);
    }
}
